
import { useState } from "react"
import { userUpload,BASE_URL } from "@monorepo/api"
import {FuiouUpload} from "@/components/comm/FuiouUpload/index"
export default function Upload(){
    const formData=new FormData(),[urlImg,setImgUrl]=useState('')
    let file=null
    function fileFn(event){
        file=event.target.files[0]
        console.log(file)
        formData.append("file", file)
        //   const formData = new FormData()
        //                 formData.append("type",type)
        //                 formData.append("imgFile", data)
    }
    function userUploadFn(){
        if(!file){
            alert("请上传图片");
            return false;
        }
        userUpload(formData).then(res=>{
            const { path,filename }=res.data
            console.log(path,filename)
            setImgUrl(BASE_URL+path)
            console.log(res)
        })
    }
    return (
       <>
            <FuiouUpload></FuiouUpload>
            <input type="file" name="file" onChange={(event)=>fileFn(event)} /> 
            <button type="button" onClick={userUploadFn}>上传文件</button>
            { urlImg?<img src={urlImg}  style={{width:"100px",height:"100px"}} />:''}
        </>
    )
}